<?php   
class ControllerConfigCommon extends Controller {
	
	protected function init(){
 		header("Access-Control-Allow-Origin: *");
 	}
	
	public function position() {
		$this->init();
		$json = array();
		if(isset($this->request->get['x'])&&isset($this->request->get['y'])){
			$s = array(array(1,1), array(2,4), array(4,4), array(4,1));
			$x =(float) $this->request->get['x'];
			$y =(float) $this->request->get['y'];
			$point = array($x,$y);
			if(getPin($s, $point)){
				$json['result'] = "Y";
			}else{
				$json['result'] = "N";
			}
		}else{
			$json['result'] = "false";
			
		}
		
		$this->response->setOutput(json_encode($json));
	} 	
	
	
	public function news(){
		$this->init();
		$this->load->model('config/news');
		$this->load->model('tool/image');
		
		$json = array();
		if(isset($this->request->get['url'])){
			$url = $this->request->get['url'];
			$json['status']  = '0';
			$articles = $this->model_config_news->getNewsArticleByUrl($url);
			if($articles){
					foreach ($articles as $article) {
						if ($article['pic_url'] && file_exists(DIR_IMAGE . $article['pic_url'])) {
							$picUrl = $this->model_tool_image->resize($article['pic_url'], 100, 100);
						} else {
							$picUrl = $this->model_tool_image->resize('no_image.jpg', 100, 100);
						}
						$json['result'][] = array(
							'title'=>$article['title'],
							'description'=>$article['description'],
							'pic_url'=>$picUrl,
							'url' =>$article['url'],
						
						);
					}
			}else{
				$json['result'] = array();
			}
		}else{
			$json['status']  = '1';
			$json['result'] = array();
		}
		$this->response->setOutput(json_encode($json));
	}
	
	
}
?>
